package com.lotustong.im4d.util;

import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileUtil {
	// TODO:tz:file copy
	public static String getFileContent(String fileName) {

		File newFile = new File(fileName);

		try {
			FileInputStream fis = new FileInputStream(newFile);
			DataInputStream dis = new DataInputStream(fis);
			byte[] buf = new byte[4096];
			StringBuffer strBuf = new StringBuffer();
			while (dis.available() > 0) {
				int readed = dis.read(buf);
				strBuf.append(new String(buf, 0, readed));
			}
			dis.close();
			return strBuf.toString();
		} catch (Exception e) {
			return e.getMessage();
		}
	}
	public static String getFiletype(String fileName){
		if(fileName!=null){
			return  fileName.substring(fileName.lastIndexOf(".")+1);
		}
		else {
			return null;
		}
	}
	public static String getFileName(String fileName){
		if(fileName==null) return "";
		String str = fileName;
		str = str.replace("\\", "/");
		str = str.substring(str.lastIndexOf("/")+1);
		return  str;
	}
	
	public static void main(String[] args){
		System.out.println(getFileName("a:/aa/a.txt"));
	}
}
